package net.pimpas.visitor;

import net.pimpas.core.serviceprovider.ServiceProvider;
import net.pimpas.core.visitor.BaseClassVisitor;
import net.pimpas.framework.PimpasFramework;
import net.pimpas.util.reflection.ReflectionUtils;

public final class ServiceProviderVisitor extends BaseClassVisitor {

	
	@Override
	public boolean accept(Class<?> clazz) {
		return (ReflectionUtils.isSubclass(clazz, ServiceProvider.class) && 
				ReflectionUtils.classHaveAnnotation(clazz, net.pimpas.core.serviceprovider.ann.ServiceProvider.class));
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public void visitClass(Class clazz) {
		net.pimpas.core.serviceprovider.ann.ServiceProvider spta = (net.pimpas.core.serviceprovider.ann.ServiceProvider) clazz.getAnnotation(net.pimpas.core.serviceprovider.ann.ServiceProvider.class);
		PimpasFramework.getInstance().registerServiceProvider(spta.serviceProviderType(), clazz);
	}
}